<template>
    <div class="center-wrapper">
        <!-- 地铁线路 -->
        <div id="subLine-controller">
            <div class="title-bg">
                <i class="iconfont metro-lineRoute"></i> 地铁线路
            </div>
            <div class="item-wrapper">
                <div
                    class="item"
                    v-for="(item, index) in subLineData"
                    :key="index"
                    @click.stop="handleItemClick(item)"
                >
                    <div
                        class="box"
                        :style="{
                            borderColor: item.color,
                            backgroundColor: item.choosed
                                ? item.color
                                : 'rgba(0,0,0,0)',
                        }"
                    ></div>
                    <span :style="{ color: '#34c5cf' }">{{
                        item.name.slice(-3)
                    }}</span>
                </div>
            </div>
        </div>
        <!-- 站点列表 -->
        <div id="station-controller">
            <div class="title-bg">
                <i class="iconfont metro-ditie"></i> 地铁站点
            </div>
            <div class="item-wrapper">
                <div
                    class="item"
                    :key="index"
                    v-for="(item, index) in stationData"
                    @click.stop="handleStationClick(item)"
                >
                    <div
                        class="box"
                        :style="{
                            backgroundColor:
                                index - 1 < metroIndex
                                    ? '#fff'
                                    : 'rgba(0,0,0,0)',
                        }"
                    ></div>
                    <span :style="{ color: '#34c5cf' }">{{ item.name }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useLineData, watchLineData } from "@/store/index";
import {focusOnStation} from '@/cesiumTools/LineMaterial/effectController'
const lineDataStore = useLineData();
const viewer = lineDataStore.viewer;

const subLineData = ref([]);
const stationData = ref([]);
const metroIndex = ref(0);
const handleItemClick = (item) => {
    let targetline = subLineData.value.find((line) => {
        return line.name === item.name;
    });
    if (targetline) {
        stationData.value = targetline.stationsList;
    }
};

const handleStationClick = (item) => {
    focusOnStation(viewer, item.name)
};

onMounted(async() => {
    subLineData.value = await watchLineData("setData");
    console.log(subLineData.value);
    stationData.value = subLineData.value[0].stationsList;
});
</script>

<style scoped>
.wrapper {
    width: 100%;
    height: 100%;
}

/* 地铁线路列表 */
#subLine-controller {
    position: absolute;
    bottom: 10%;
    left: 32.5%;
    transform: translateX(-50%);
    width: 180px;
    height: 200px;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid #ab7818;
    display: flex;
    flex-direction: column;
}

.box {
    width: 10px;
    height: 10px;
    border-width: 1px;
    border-style: solid;
    background: transparent;
    user-select: all;
    cursor: pointer;
    transition: all 0.3s linear;
}

.item {
    width: 64.992px;
    height: 20.006px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.156vw;
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid #885f12;
    color: #fff;
    font-size: 0.521vw;
    pointer-events: all;
}

.item:hover {
    border: 1px solid #d8961a;
}

.item > span {
    line-height: 0.469vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 2.083vw;
}

.item > input {
    outline: none;
    border: none;
    transition: all 0.3s ease;
}

.item-wrapper {
    display: flex;
    justify-content: space-around;
    align-content: space-around;
    flex-wrap: wrap;
    flex: 1;
    padding: 4px;
    overflow: hidden;
}

/* 站点列表 */
#station-controller {
    width: 600px;
    height: 200px;
    border: 1px solid #ab7818;
    background-color: rgba(0, 0, 0, 0.3);
    position: absolute;
    left: 38%;
    bottom: 10%;
    color: #fff;
    display: flex;
    flex-direction: column;
}

#station-controller .item-wrapper {
    justify-content: flex-start;
}

#station-controller .item {
    margin: 0 7px;
}

.title-bg {
    width: 100%;
    height: 30px;
    background: url("/src/assets/uiResources/title-bg.png");
    background-size: contain;
    color: #fff;
    background-repeat: no-repeat;
    line-height: 30px;
    margin-left: 10px;
    background: rgb(255, 255, 255);
    background-image: linear-gradient(
        180deg,
        rgba(255, 255, 255, 1) 9%,
        rgba(211, 156, 50, 1) 57%
    );
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* 站控措施图例 */
.right-wrapper {
    width: 11.417vw;
    height: 100%;
    position: absolute;
    right: 0px;
    top: 2.083vw;
}

.right-wrapper .query-item-title {
    cursor: default;
    pointer-events: none;
}

.right-wrapper .query-item-title::after {
    width: 20px;
    left: -20px;
}

.legend .query-item i {
    pointer-events: none;
    cursor: default;
}

.title {
    color: #fff;
}
</style>
